<template>
  <div>
    <el-table :data="reslist" border style="width: 100%">
      <el-table-column fixed prop="uid" label="UID" width="200">
      </el-table-column>
      <el-table-column prop="mobile" label="手机号" width="200">
      </el-table-column>
      <el-table-column prop="avatar" label="头像" width="200">
        <template slot-scope="scope">
          <img :src="scope.row.avatar" width="50" />
        </template>
      </el-table-column>
      <el-table-column prop="nickname" label="姓名" width="200">
      </el-table-column>
      <el-table-column prop="status" label="状态" width="200">
      </el-table-column>
      <el-table-column prop="created_at" label="时间" width="200">
        <template slot-scope="prop">
          <span>{{ prop.row.created_at | timeFilters }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="caozuo" label="操作" width="145">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope, index)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="list.length"
      :page-size="pagesize"
      :current-page="pagenumber"
      @current-change="Change"
    >
    </el-pagination>
    <!-- 编辑 -->
    <el-dialog title="修改状态" :visible.sync="abc">
      <el-form :model="form">
        <el-form-item label="姓名">
          <el-input v-model="form.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="form.mobile" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="abc = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      pagesize: 5,
      pagenumber: 1,
      abc: false,
      form: {
        nickname: "",
        mobile: "",
        uid: "",
      },
    };
  },
  computed: {
    reslist() {
      return this.list.slice(
        this.pagesize * (this.pagenumber - 1),
        this.pagesize * this.pagenumber
      );
    },
  },
  filters: {
    timeFilters: function (val) {
      var time = new Date(val * 1000);
      return `${time.getFullYear()}年${time.getMonth()}月${time.getDay()}日${time.getHours()}时${time.getMinutes()}分${time.getUTCMinutes()}秒`;
    },
  },
  mounted() {
    this.$axios.get("/list.json").then((res) => {
      //    console.log(res.data);
      this.list = res.data;
    });
  },
  methods: {
    add(props) {
      console.log(props);
    },
    Change(val) {
      this.pagenumber = val;
    },
    handleDelete(index) {
      this.list.splice(index, 1);
    },
    handleEdit(item) {
      this.abc = true;
      this.form = item;
    },
    confirm() {
      this.abc = false;
      this.list.forEach((item) => {
        if ((item.uid = this.form.uid)) {
          item.nickname == this.form.nickname;
          item.mobile == this.form.mobile;
        }
      });
    },
  },
};
</script>

<style lang="scss">
* {
  padding: 0;
  margin: 0;
}
</style>